babl: make error argument of babl_space_from_icc optional
authorØyvind Kolås <pippin@gimp.org>
Sun, 3 Sep 2017 13:06:37 +0000 (15:06 +0200)
committerØyvind Kolås <pippin@gimp.org>
Sun, 3 Sep 2017 13:06:37 +0000 (15:06 +0200)
babl/babl-icc.c
babl/babl-internal.h
babl/babl.h

index a79f21b1d2788eb71ebd3ba23433f538161ef22b..3fa24e9a59b56e6ad9a1579b81be7ad090233b67 100644 (file)
@@ -300,7 +300,7 @@ static int icc_tag (ICC *state,
 }
 
 static const Babl *babl_trc_from_icc (ICC  *state, int offset,
-                                      char **error)
+                                      const char **error)
 {
   {
     int count = icc_read (u32, offset + 8);
@@ -417,25 +417,13 @@ switch (trc->type)
     icc_write (u32, state->o + 8, 0);
     break;
   case BABL_TRC_FORMULA_GAMMA:
-    icc_allocate_tag (state, name, 14);
-    icc_write (sign, state->o, "curv");
-    icc_write (u32, state->o + 4, 0);
-    icc_write (u32, state->o + 8, 1);
-    icc_write (u8f8, state->o + 12, trc->gamma);
-    break;
   case BABL_TRC_GAMMA_1_8:
-    icc_allocate_tag (state, name, 14);
-    icc_write (sign, state->o, "curv");
-    icc_write (u32, state->o + 4, 0);
-    icc_write (u32, state->o + 8, 1);
-    icc_write (u8f8, state->o + 12, 1.8);
-    break;
   case BABL_TRC_GAMMA_2_2:
     icc_allocate_tag (state, name, 14);
     icc_write (sign, state->o, "curv");
     icc_write (u32, state->o + 4, 0);
     icc_write (u32, state->o + 8, 1);
-    icc_write (u8f8, state->o + 12, 2.2);
+    icc_write (u8f8, state->o + 12, trc->gamma);
     break;
   case BABL_TRC_LUT:
     icc_allocate_tag (state, name, 13 + trc->lut_size * 2);
@@ -634,9 +622,9 @@ static char *icc_decode_mluc (ICC *state, int offset, int element_length, char *
 }
 
 const Babl *
-babl_space_from_icc (const char *icc_data,
-                     int         icc_length,
-                     char      **error)
+babl_space_from_icc (const char  *icc_data,
+                     int          icc_length,
+                     const char **error)
 {
   ICC  *state = icc_state_new ((char*)icc_data, icc_length, 0);
   int   profile_size    = icc_read (u32, 0);
@@ -644,11 +632,15 @@ babl_space_from_icc (const char *icc_data,
   const Babl *trc_red   = NULL;
   const Babl *trc_green = NULL;
   const Babl *trc_blue  = NULL;
+  const char *int_err;
   char *descr     = NULL;
   char *copyright = NULL;
 
   sign_t profile_class, color_space;
 
+  if (!error) error = &int_err;
+  *error = NULL;
+
   if (profile_size != icc_length)
   {
     *error = "icc profile length inconsistency";
index c7c87cf9f67ebee40710172b6d2702453a2bc88a..6593862ce69a5a4ad569dfb12fe797eb9f8805ab 100644 (file)
@@ -349,9 +349,6 @@ babl_trc_new (const char *name,
 void babl_space_to_xyz   (const Babl *space, const double *rgb, double *xyz);
 void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb);
 
-const Babl *babl_space_from_icc (const char *icc,
-                                 int         length,
-                                 char      **error);
 const Babl *babl_trc_lut_find (float *lut, int lut_size);
 const Babl *babl_trc_lut      (const char *name, int n, float *entries);
 
index a992dad835f8fbdf9d2384b281737d039c645d01..3527a604cfb3a20c261bc11fb60cbddf4a75baf0 100644 (file)
@@ -146,28 +146,32 @@ babl_space_from_rgbxyz_matrix (const char *name,
 /**
  * babl_space_from_icc:
  *
+ * @icc_data: pointer to icc profile in memory
+ * @icc_length: length of icc profile in bytes
+ " @error: pointer to a string where decoding errors can be stored,
+ *         if an error occurs, NULL is returned and an error message
+ *         is provided in error.
+ *
  * Create a babl space from an in memory ICC profile, the
  * profile does no longer need to be loaded for the space to work,
  * multiple calls with the same icc profile will result in the
  * same space.
  *
- * For now, limited to v2 ICC profiles, support for v4 profiles will be added.
- *
- * babl uses internal parametric TRCs when the provided LUTs are sufficiently
- * similar.
- *
  * If a BablSpace cannot be created from the profile NULL is returned and
  * a static string is set on the provided error location.
  */
-const Babl *babl_space_from_icc (const char *icc_data,
-                                 int         icc_length,
-                                 char      **error);
+const Babl *babl_space_from_icc (const char  *icc_data,
+                                 int          icc_length,
+                                 const char **error);
 
 
 /* babl_space_to_icc:
  *
  * Creates an ICCv2 RGB matrix profile for a babl space. The profiles strive to
  * be as small and compact as possible, TRCs are stored as 1024 entry LUT(s).
+ *
+ * you should make a copy of the profile before making another call to this
+ * function.
  */
 const char *babl_space_to_icc (const Babl *space, int *icc_length);